var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var port = process.env.NODE_PORT || 8080;

module.exports = {
    entry: [
        'react-hot-loader/patch',
        'webpack-dev-server/client?http://localhost:'+port,
        'webpack/hot/only-dev-server',
        './src/index.js'
    ],
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist'),
        publicPath: ''
    },
    module: {
        rules: [{
            test: /.jsx?$/,
            exclude: /node_modules/,
            use: ['babel-loader']
        },{
            test: /\.css$/,
            use: ['style-loader', 'css-loader']
        },{
            test: /\.scss$/,
            use: ['style-loader', 'css-loader', 'sass-loader']
        },{
            test: /\.(png|jpg|gif|jpeg)$/,
            use: [{
                loader: 'file-loader',
                options: {
                    limit: 10000,
                },
            }]
        },{
            test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
            use: ['file-loader']
        }]
    },
    resolve:{
        extensions: ['.js', '.jsx', '.json', ".css", ".sass"],
    },
    devtool: 'source-map', /*实现错误提示映射到源码*/
    
	plugins: [
       new CleanWebpackPlugin(['dist']),
       new HtmlWebpackPlugin({
           filename: 'index.html',
           template: 'src/index.html'
       }),
       new webpack.HotModuleReplacementPlugin()
    ]
}
